package com.gxwy.yonghuziliao.controller;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.gxwy.jiaoyi.form.JiaoYi;
import com.gxwy.jiaoyi.service.JiaoYiService;
import com.gxwy.yonghuziliao.form.YongHuZiLiao;
import com.gxwy.yonghuziliao.service.YongHuZiLiaoService;
import com.gxwy.zizhanghu.form.ZiZhangHu;
import com.gxwy.zizhanghu.service.ZiZhangHuService;

@Controller
@RequestMapping("/yonghuziliao")
public class SelectJiaoYiMingXiController {

	@Autowired
	private YongHuZiLiaoService  service;
	
	@Autowired
	private ZiZhangHuService service1;
	
	@Autowired
	private JiaoYiService service2;
	
	@RequestMapping("/tojymxcx")
	public String tojymxcx(Model model,HttpSession session){
		String username=(String) session.getAttribute("username");
		List<YongHuZiLiao> list=service.findAll(username);			
		int size=list.size();
		model.addAttribute("yonghuziliao",list);
		model.addAttribute("size",size);
		return "jymxcx";
	}
	
	@RequestMapping("/tojymxcx1/{no}")
	public String tojymxcx1(Model model,@PathVariable("no")String no){
		YongHuZiLiao yhzl=service.findByZhangHao(no);
		ZiZhangHu zzh=service1.findByZhangHuZhangHao(no);
		model.addAttribute("yhzl",yhzl);
		model.addAttribute("zzh",zzh);
		return "jymxcx1";
	}
	
	@RequestMapping("/tojymxcx2")
	public String tojymxcx2(Model model,@RequestParam("yinhangzhanghao")String yhzh,@RequestParam("qishiriqi")String qsrq,@RequestParam("jiezhiriqi")String jzrq){
		YongHuZiLiao yhzl=service.findByZhangHao(yhzh);
		ZiZhangHu zzh=service1.findByZhangHuZhangHao(yhzh);
		List<JiaoYi> list=service2.chaxunjiaoyimingxi(yhzh, qsrq, jzrq+" 23:59:59");
		float shouru=0f;
		float zhichu=0f;
		for(JiaoYi jy:list){
			if("0".equals(jy.getZhuanruzhuanchu())){
				zhichu+=jy.getJiaoyijine();
			}else{
				shouru+=jy.getJiaoyijine();
			}
		}
		model.addAttribute("sr",shouru);
		model.addAttribute("zc",zhichu);
		model.addAttribute("list",list);
		model.addAttribute("yhzl",yhzl);
		model.addAttribute("zzh",zzh);
		model.addAttribute("qsrq",qsrq);
		model.addAttribute("jzrq", jzrq);
		return "jymxcx2";
	}
}
